<?php
/**
 * 故障类型
 * @author hezhong
 */
class Car_fault_type_model extends CI_Model
{
    public function select_list($param = array(
        'typename'=>'',
        'start'=>0,
        'length'=>10
    )) {

        if($param['typename']) {
            $this->db->like('typename',$param['typename']);
        }

        $data['count'] = $this->db->count_all_results('car_fault_type');

        $this->db->from('car_fault_type');
        $this->db->order_by("typeid", "asc");
        $this->db->limit($param['length'], $param['start']);

        if($param['typename']) {
            $this->db->like('typename',$param['typename']);
        }

        $query = $this->db->get();

        $data['list'] = $query->result_array();

        return $data;
    }

    public function select_by_parentid($parentid = 0)
    {
        $query = $this->db->get_where('car_fault_type', array('parentid' => $parentid));
        return $query->result_array();
    }

    public function insert_type()
    {
        $data = array(
            'typename' => $this->input->post('typename'),
            'parentid' => $this->input->post('typeid')
        );

        $this->db->insert('car_fault_type', $data);
    }

    public function select_by_id($typeid)
    {
        $this->db->where('typeid',$typeid);
        $query = $this->db->get('car_fault_type');
        $row = $query->row_array();
        return $row;
    }

    public function update($typeid, $typename, $parentid) {
        $fields['typename'] = $typename;
        $fields['parentid'] = $parentid;

        $this->db->where('typeid', $typeid);
        $this->db->update('car_fault_type', $fields);
    }

    function delete($typeid)
    {
        $this->db->where('typeid',$typeid);
        $this->db->delete('car_fault_type');
    }
}